package in.muton.edushare.components.tasks.electives;

import in.muton.edushare.pages.common.EdusharePanel;
import in.muton.edushare.pages.coursepages.CoursePage;
import in.muton.edushare.url.EntityPageParams;
import in.muton.edushare.wicket.models.CayenneList;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.IModel;

import com.edushare.common.dao.CurriculumDAO;
import com.edushare.common.dao.ElectivePreferenceDAO;
import com.edushare.common.vo.Courses;
import com.edushare.common.vo.Curricula;
import com.edushare.common.vo.Users;

public class CompletedUniqueElectivePanel extends EdusharePanel {

	public CompletedUniqueElectivePanel(String id,
			final IModel<Curricula> currmodel, IModel<Users> userModel,
			final Integer currSemester, final Integer groupId) {
		super(id);
		CurriculumDAO cDAO = new CurriculumDAO(getORMInterface());
		CayenneList<Courses> courseList = new CayenneList<Courses>(cDAO
				.getElectiveCourses(currmodel.getObject(), currSemester,
						groupId));

		add(new Label("electiveGroup","Elective - " + (groupId+1) + " of "
				+ currmodel.getObject().getCurriculaName()+" for semester "+ (currSemester+1) +"."));
		
		add(new ListView<IModel<Courses>>("choiceListLV", courseList) {
			@Override
			protected void populateItem(final ListItem<IModel<Courses>> arg0) {
				Link<Void> l;
				arg0.add(new Label("serialNo", Integer
						.toString(arg0.getIndex()+1)));
				arg0.add(l = new BookmarkablePageLink<Void>("courseLink",
						CoursePage.class, EntityPageParams.getParams(arg0
								.getModelObject())));

				l.add(new Label("courseName", arg0.getModelObject().getObject()
						.getCourseName()));

				ElectivePreferenceDAO eDAO = new ElectivePreferenceDAO(
						getORMInterface());
				CurriculumDAO cDAO = new CurriculumDAO(getORMInterface());
				arg0.add(new Label("preference", eDAO
						.getPreference(getLoggedInUser(), cDAO.getSemCourse(
								currmodel.getObject(), currSemester, groupId,
								arg0.getModelObject().getObject()), groupId).getPreferenceNumber().toString()));

			}

			private static final long serialVersionUID = -4006228290877116122L;
		});

	}

	private static final long serialVersionUID = 5563319747742492019L;
}
